<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="88px">
      <el-form-item label="园所性质：" prop="schoolType">
          <el-select v-model="queryParams.schoolType" placeholder="请选择园所性质" clearable size="small">
            <el-option v-for="dict in schoolTypeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
          </el-select>
         </el-form-item>
      <el-form-item label="地区类型：" prop="nature">
        <el-select v-model="queryParams.nature" placeholder="请选择地区类型" clearable size="small">
          <el-option v-for="dict in schoolNatureOptions" :key="dict.dictValue" :label="dict.dictLabel"
            :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="园所名称：" prop="schoolName">
        <el-input @input="handleInput" v-model="queryParams.schoolName" placeholder="请输入园所名称" clearable size="small" />
      </el-form-item>
      <el-form-item label="获奖时间" prop="dateRange">
        <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" :editable="false"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :picker-options="pickerOptions"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="bear">
      <el-table-column type="index" label="序号" align="center" :index="customeIndex" width="80"></el-table-column>
      <el-table-column label="园所名称" align="center" prop="schoolName" />
      <el-table-column align="center" label="园所性质" prop="schoolType" :formatter="schoolTypeFormat"></el-table-column>
      <el-table-column align="center" label="地区类型" prop="nature" :formatter="schoolNatureFormat"></el-table-column>
      <el-table-column label="国家级" align="center" prop="level1" />
      <el-table-column label="省市级" align="center" prop="level2" />
      <el-table-column label="区县级" align="center" prop="level3" />
      <!-- <el-table-column label="获奖时间" align="center" prop="getTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.getTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetails(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog title="获奖详情" :visible.sync="open" width="800px" append-to-body>
      <el-table v-loading="loading" :data="specificList">
        <el-table-column type="index" label="序号" align="center" :index="customeIndex" width="80"></el-table-column>
        <el-table-column label="奖项等级" align="center" prop="level" :formatter="levelFormat" />
        <el-table-column label="奖项名称" align="center" prop="title" />
        <el-table-column label="获奖时间" align="center" prop="getTime"></el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="specificTotal" :page.sync="querys.pageNum" :limit.sync="querys.pageSize"
        @pagination="getList" />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { regionListdetail, specificDetail } from "@/api/qu/byjx";
export default {
  name: "School",
  data() {
    return {
      // 遮罩层
      loading: true,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      // 选中数组
      ids: [],
      bear: [],
      // 总条数
      total: 0,
      // 是否显示弹出层
      open: false,
      schoolNatureOptions: [],
      schoolTypeOptions: [],
      // 奖项类型字典
      typeOptions: [],
      // 奖项级别字典
      levelOptions: [],
      specificList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        type: null,
        level: null,
        depart: null,
        getTime: null,
        area: null,
        nature: null,
        schoolName: null
      },
      querys: {
        pageNum: 1,
        pageSize: 10,
      },
      specificTotal: 0,
      // 表单参数
      form: {},
      // 日期范围
      dateRange: [],
    };
  },
  created() {
    this.getList();
    this.getDicts("glory_level").then(response => {
      this.levelOptions = response.data;
    });
    this.getDicts("school_nature").then(response => {
      this.schoolNatureOptions = response.data;
    });
    this.getDicts("date_type").then(response => {
      this.dateTypeOptions = response.data;
    });
    this.getDicts("park_type").then(response => {
      this.schoolTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询高光时刻列表 */
    async getList() {
      this.loading = true;
      try {
        const obj = {
          nature: this.queryParams.nature,
          area: this.queryParams.area,
          schoolName: this.queryParams.schoolName,
          'params[beginTime]': this.dateRange[0],
          'params[endTime]': this.dateRange[1],
          schoolType:this.queryParams.schoolType
        }
        const data = await regionListdetail(obj);
        this.bear = data.rows;
        this.total = data.total;
        this.loading = false;
      } catch (error) {
        console.log(error);
      }
    },
    // 序号
    customeIndex(index) {
      return index + 1 + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
    },
    // 园所性质字典翻译
    schoolTypeFormat(row, column) {
      return this.selectDictLabel(this.schoolTypeOptions, row.schoolType);
    },
    //地区类型字典翻译
    schoolNatureFormat(row, column) {
      return this.selectDictLabel(this.schoolNatureOptions, row.nature);
    },
    // 奖项级别字典翻译
    levelFormat(row, column) {
      return this.selectDictLabel(this.levelOptions, row.level);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        type: null,
        level: null,
        depart: null,
        getTime: null,
        comment: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    handleInput(val) {
      let regtszf = /[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘'，。、]/g // 特殊字符正则
      let regkg = /[ ]/g// 空格正则
      this.queryParams.schoolName = val.replace(regtszf, '').replace(regkg, '')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //具体奖项明细
    async getSpecificDetail(val) {
      try {
        const obj = {
          schoolCode: val.schoolCode,
          pageNum: this.querys.pageNum,
          pageSize: this.querys.pageSize,

        }
        const data = await specificDetail(obj)
        this.specificList = data.rows;
        this.specificTotal = data.total;
      } catch (error) {

      }
    },
    //详情
    handleDetails(val) {
      this.getSpecificDetail(val);
      this.open = true;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加高光时刻";
    },
    /** 提交按钮 */
    submitForm() {
      this.open = false;

    },

  }
};
</script>
